<%@ taglib prefix="form" uri="http://www.springframework.org/tags/form" %>
<%@taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
	<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
	<script type="text/javascript" src="resources/js/jquery/jquery-1.10.2.js"></script>
	<script src="resources/bootstrap/js/bootstrap.min.js"></script>
	<link rel="stylesheet" href="resources/css/style.css"></link>
	<link href="resources/bootstrap/css/bootstrap.min.css" rel="stylesheet" />
	<script type="text/javascript">
		var jq = jQuery.noConflict();
	</script>
</head>
<body>
	<div id="container">
	
	<jsp:include page="menubar.jsp"></jsp:include>
		
		
	<jsp:include page="right_sidebar.jsp"></jsp:include>
		
	<div id="content" style="width: 72%; margin-left: 5%">
	<center>
		<h1>Edit of ${product.name}</h1>
	</center>
	
	<form:form method="post"  commandName="productForm" enctype="multipart/form-data" >
		<img width="25%" src="resources/img/${product.idProduct}.jpg">
		Image: <input type="file" name="file" onChange="return check()"><br>
		<table width="100%">
			<tr>
				<td width="10%" >Name:</td>
				<td width="70%" ><form:input path="name" class="text" /></td>
				<td><span class="error"><form:errors path="name" /></span></td>
			</tr>

			<tr>
				<td>Description:</td>
				<td><form:input path="description" class="text" /></td>
				<td><span class="error"><form:errors path="description" /></span></td>
			</tr>

			<tr>
				<td>Cost:</td>
				<td><form:input path="cost" class="text" /></td>
				<td><span class="error"><form:errors path="cost" /></span></td>
			</tr>

			<tr>
				<td>Weight:</td>
				<td><form:input path="weight" class="text" /></td>
				<td><span class="error"><form:errors path="weight" /></span></td>
			</tr>
			
			<tr>
				<td>Quantity:</td>
				<td>
					<form:input path="quantity" class="text" />
					<form:input path="idProduct" type="hidden"  value="${product.idProduct}"/>
				</td>
				<td><span class="error"><form:errors path="quantity" /></span></td>
			</tr>

			<tr>
				<td colspan="3"><input type="submit" value="Submit" /></td>
			</tr>
		</table>
	</form:form>
	
	
	</div>
	</div>
	
	<jsp:include page="footer.jsp"></jsp:include>


	<script type="text/javascript" language="JavaScript">
	function check() {
  		var ext = document.product.file.value;
 		ext = ext.substring(ext.length-3,ext.length);
  		ext = ext.toLowerCase();
  		if(ext != 'jpg') {
    		alert('You selected a .'+ext+' file; please select a .jpg file instead!');
    		return false; }
  		else
    		return true; }
	</script>
	
</body>
</html>